<template>
  <div class="xhhzcx_box">
    <header-comm></header-comm>
    <!-- 表格 -->
    <div class="bcg left_bcg">
      <div class="hedlist">
        <div class="head_box">
          <div></div>
          <div class="sele">
            <!-- <a-auto-complete v-model="search_val" :data-source="searchData" allowClear  class="global-search"    style="width: 200px"  @search="onXmphoneSearch" @select="onXmphoneSelect" size="large"  placeholder="请输入姓名或手机" >
                            <template slot="XlData">
                                <a-select-option v-for="(search,i) in searchData" :key="i" >
                                    {{search}}
                                </a-select-option>
                            </template>
                            <a-input>
                                <a-button 
                                slot="suffix"
                                style="margin-right: -12px"
                                class="search-btn"
                                size="large"
                                >
                                <a-icon type="search" />
                                </a-button>
                            </a-input>
                        </a-auto-complete>
            -->
            <!-- {{searchData}} -->
            <a-select
            allowClear
              show-search
              placeholder="请输入姓名或手机"
              option-filter-prop="children"
              style="width: 200px"
              :filter-option="filterOption"
              @focus="handleFocus"
              @blur="handleBlur"
              @change="onXmphoneSelect"
              @search="onXmphoneSearch"
            >
              <a-select-option :value="item" v-for="(item, i) in searchData" :key="i">{{item}}</a-select-option>
            </a-select>
          </div>
        </div>
        <div class="gl_tjwz" v-if="$store.state.tjwz">
          <smtlxrxq :record="record" class="gl_tjym"></smtlxrxq>
        </div>
      </div>
      <div class="xhhzcx_table">
        <a-table
          @change="getlxrlist"
          :loading="loading"
          :columns="columns"
          :pagination="pagination"
          :dataSource="data"
          :rowKey="(record,index)=>{return index}"
        >
          <template slot="lxrxq" slot-scope="text, record,">
            <div
              style="overflow: hidden;text-overflow: ellipsis; width:100px; white-space: nowrap; c"
            >
              <a @click="()=>lxrxq(record)">所属客户</a>
            </div>
          </template>
        </a-table>
      </div>
    </div>
    <rightnav></rightnav>
  </div>
</template>
<script>
import qs from "qs";
import moment from "moment";
import headerComm from "../../header-comm/header";
import smtlxrxq from "./smtlxrxq.vue";
import rightnav from "../rightnav.vue";
// 引入表格的列
const columns = [
  {
    title: "联系人",
    dataIndex: "lxr",
    scopedSlots: { customRender: "lxr" }
  },
  {
    title: "单位名称",
    dataIndex: "dwmc",
    scopedSlots: { customRender: "dwmc" }
  },
  //   {
  //       title:"联系电话",
  //       dataIndex: "lxdh",
  //     //   width:150,
  //     scopedSlots: { customRender: "lxdh" },
  //   },
  {
    title: "手机",
    dataIndex: "phone"
    //   width:200,
  },
  {
    title: "操作",
    dataIndex: "lxrxq",
    fixed: "right",
    width: 100,
    scopedSlots: { customRender: "lxrxq" }
  }
];
export default {
  data() {
    return {
      // 表格数据
      data: null,
      columns,
      loading: true,
      // 公司编码
      gsbm: "",
      // 授权id
      sqdwid: "",
      //数据库名称
      database: "ERP2_BEARING",
      // ip地址
      ip: "122.112.240.180",
      // 联系人或phone值
      search_val: "",
      // 模糊查询数组
      searchData: [],
      // 联系人列表
      lxrList: [],
      // 分页数据
      pagination: {
        defaultPageSize: 10,
        current: 1,
        showTotal: total => `共 ${total} 条数据`,
        total: 0
      },
      // 传参数据
      record: ""
    };
  },

  methods: {
    //关闭弹出框
    close() {
      this.$store.state.wzfl = false;
    },
    // 联系人详情
    lxrxq(record) {
      console.log(record);
      this.record = record;
      console.log(this.record);
      this.$store.state.tjwz = true;
    },
    // 姓名手机搜索触发
    onXmphoneSearch(e) {
      this.search_val = e;
      console.log(e);
      this.getlxrlist(this.pagination);
    },
    // 姓名手机选择触发
    // onXmphoneSelect(e) {
    //   this.search_val = e;
    // },
    //// 获取表格数据
    getlxrlist(pagination) {
      this.pagination.current = pagination.current;
      this.axios
        .post(
          "https://yb.bearing.cn/wxapi/smt_newLxrList.php",
          qs.stringify({
            page: this.pagination.current,
            gsbm: this.gsbm,
            pageSize: this.pagination.defaultPageSize,
            database: this.database,
            keywords: this.search_val,
            token:sessionStorage.getItem('smt_token'),
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 103) {
            this.loading = false;
            this.pagination.total = Number(res.data.result.totalDataNum);
            // 去重筛选搜索提示
            let searchsj = [];
            for (var i = 0; i < res.data.result.resDate.length; i++) {
              searchsj.push(res.data.result.resDate[i].lxr);
              searchsj.push(res.data.result.resDate[i].phone);
            }
            this.searchData = searchsj;
            this.searchData = new Set(searchsj);
            this.searchData = Array.from(this.searchData);
            this.searchData = this.searchData.filter(function(s) {
              return s && s.trim();
            });

            console.log(this.searchData);
            this.data = res.data.result.resDate;
          } else {
            // this.totalNum = Number(0);
            this.loading = false;
            this.data = [];
          }
        });
    },
    onXmphoneSelect(value) {
      console.log(`selected ${value}`);
        this.search_val = value;
      console.log(value);
      this.getlxrlist(this.pagination);
    },
    handleBlur() {
      console.log("blur");
    },
    handleFocus() {
      console.log("focus");
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    }
  },
  components: {
    headerComm,
    rightnav,
    smtlxrxq
  },
  created() {
    this.gsbm = sessionStorage.getItem("gsbm");
    this.genjinInfo = JSON.parse(sessionStorage.getItem("genjinInfo"));
    this.getlxrlist(this.pagination);
  }
};
</script>

<style lang='less' scoped>
.xhhzcx_box {
  .hedlist {
    position: fixed;
    z-index: 999;
    width: 71%;
    left: 10%;
    top: 50px;
    height: 90px;
    line-height: 60px;
    background-color: #f3f7f9;
    .head_box {
      width: 100%;
      display: flex;
      justify-content: space-between;
      background-color: #fff;
      padding: 0 20px;
      .sele {
        position: relative;
        text-align: left;
        /deep/ .ant-select-auto-complete.ant-select .ant-input {
          height: 32px !important;
        }
        /deep/ .ant-select-selection__clear {
          right: 50px !important;
        }
        .ant-btn-lg {
          height: 32px !important;
        }
        .search {
          position: absolute;
          top: 8px;
          right: 120px;
          font-size: 18px;
        }
      }
    }
    .list_head {
      display: inline-block;
      margin-right: 10px;
    }
    .ssgs_box {
      display: inline-block;
      margin-right: 20px;
    }
  }
  .bcg {
    width: 90%;
    background-color: #f3f7f9 !important;
    position: relative;
    left: 10%;
    min-height: 1000px;
    .xhhzcx_table {
      position: relative;
      left: 1%;
      top: 140px;
      width: 98%;
      text-align: left;
      padding: 20px;
      background: #fff;

      .ant-table-scroll {
        word-break: break-all;
      }
      .ant-table-thead {
        background-color: #ccc !important;
      }
      .ant-table-tbody {
        background: #fff !important;
      }
      .ant-table-tbody > td.colme {
        color: red !important;
      }
    }

    .ant-pagination {
      float: right !important;
      margin-top: 20px;
    }
  }
  .prev_btn {
    position: relative;
    top: 15px;
    left: 650px;
    margin-bottom: 30px;
  }
  .next_btn {
    position: relative;
    top: 15px;
    left: 675px;
    margin-bottom: 30px;
  }
}
</style>
